angular.module('jisuStuHome').controller('publictask', ['$scope', '$rootScope', '$state', '$timeout', 'StuRequestTrain', 'RequestTrainService', 'sysUserInfo', 'Msg', 'MsgCon', 'LS', 'T','$stateParams', function ($scope, $rootScope, $state, $timeout, ST, RTS, sysUserInfo, Msg, MsgCon, LS, T,$stateParams) {
    $scope.change = 2
    $scope.stageTrainObj =  $stateParams.renwuobj
    if(!$stateParams.renwuobj) {
        $state.go('home.train.task')
        return
    }
    //返回
    $scope.taskObj= "=",   // 培训计划对象
    $scope.onClose="&",    //关闭窗口            
    $scope.showKnow="=",//是否需要题库    
    // console.log($scope.stageTrainObj);
    //文件预览 
    $scope.isFilePreview = { divhide: false, data: {} };
    // 文件预览
    $scope.filePreview = function (item) {
        $scope.isFilePreview.divhide = true;
        $scope.isFilePreview.data = item;
    }
    $scope.changetab = function(val){
        // console.log(val);
        
        $scope.change = val
     
    }
    $scope.backClose=function(){
        //判断返回的是哪儿
        if($stateParams.renwuobj.hasOwnProperty('arragetype')&&!$scope.stageTrainObj.hasOwnProperty('arragetype')){
            //是任务详细页跳转知识分类页
            
            $scope.stageTrainObj=$stateParams.renwuobj
            $scope.init();
        }else{
            history.back();
        }
    }
    $scope.init = function(){
        // 是否查看全部信息 4种
        $scope.isTrainList = "1";
        if($scope.isTrainList == 5) {
            Msg.warning("提示", "任务已过期!");
            return;
            }
        if($scope.isTrainList == 6) {
            Msg.warning("提示", "未到任务开始时间!");
            return;
        }
        //任务需要报名，并且是第一次展开
        if ($scope.stageTrainObj.isReviewed && $scope.stageTrainObj.signUpState == undefined) {
            $scope.stageTrainObj.signUpState = 0; //0初始 1审核中 2已通过 3失败
            $scope.stageTrainObj.warnMsg = "注意：此任务需要学员报名参与并且管理员审核后才可开始学习！";
            //查询是否报名
            RTS.getEnrollInfo({ xid: $scope.stageTrainObj.id, userid: sysUserInfo.getuserinfo().user_ID, xtype: 1 }).then(function (response) {
                if (response.errorcode == 0 && response.data != null && response.data != undefined && response.data != "") {
                    $scope.stageTrainObj.signUpState = response.data.reviewed;
                    if ($scope.stageTrainObj.signUpState == 1) {
                        $scope.stageTrainObj.warnMsg = "您的报名申请已提交，正在审核中，请耐心等待！";
                    } else if ($scope.stageTrainObj.signUpState == 2) {
                        $scope.stageTrainObj.warnMsg = "您的报名申请已通过审核！";
                    } else if ($scope.stageTrainObj.signUpState == 3) {
                        $scope.stageTrainObj.warnMsg = "您的报名申请未通过审核，详情请联系管理员！";
                    }
                }

                
            });
        }
        //已完成的id
        $scope.completeStr=-1;
        // loading
        $scope.isRequestLoading = false;
        // 当前阶段
        $scope.selStageFlag = 1;
        // 阶段课程列表
        $scope.stageCourseList = [];
        //初始化课程的请求参数
        $scope.courseParams = {
            courseids: [],   //课程id
            paperids: [], // 试卷id
            upids: [],   //文件id
            knowledgeids: [],    // 知识结构id
            pageIndex: 1,
            pageSize: 5
        }
        $scope.stageTrainObj.isOpen = !$scope.stageTrainObj.isOpen;
        //汇总数据集合,为了排序 &&typeof(scope.stageTrainObj.arragetype)=="string"
        if ($scope.stageTrainObj.hasOwnProperty('arragetype')){                   
            if($scope.stageTrainObj.arrage!=undefined&&typeof($scope.stageTrainObj.arrage)=="string"){
                $scope.stageTrainObj.arrage=JSON.parse($scope.stageTrainObj.arrage);
            }
            if($scope.stageTrainObj.arragetype!=undefined&&typeof($scope.stageTrainObj.arragetype)=="string"){
                $scope.stageTrainObj.arragetype=JSON.parse($scope.stageTrainObj.arragetype);
            }
            $scope.stageTrainObj.arragetype.forEach(function(keyObj,index){
                var totleList=[];
                    if (keyObj.hasOwnProperty('kssList')){ // 知识结构
                        keyObj.kssList.forEach(function(data,index){
                            data.type=3;
                            if(data.order==undefined||data.order==null||data.order==""){
                                data.order=0;
                            }
                            totleList.push(data);
                        });
                }
                if (keyObj.hasOwnProperty('kseList')){ // 试卷
                        keyObj.kseList.forEach(function(data,index){
                            data.type=2;
                            if(data.order==undefined||data.order==null||data.order==""){
                                data.order=0;
                            }
                            totleList.push(data);
                        });
                }
                if (keyObj.hasOwnProperty('kscList')){ //课程
                        keyObj.kscList.forEach(function(data,index){
                            data.type=1;
                            if(data.order==undefined||data.order==null||data.order==""){
                                data.order=0;
                            }
                            totleList.push(data);
                        });
                }
                keyObj.totleList=totleList;
                //强制任务学习才排序
                // console.log($scope.stageTrainObj.arrage);
                
                if ($scope.stageTrainObj.arrage.isOrder!=undefined&&$scope.stageTrainObj.arrage.isOrder){
                    keyObj.totleList=keyObj.totleList.sort(function(obj1,obj2){
                        return obj1.order-obj2.order;
                    })
                }
            });   
            //scope.selStage(scope.stageTrainObj.arragetype[0],1);
            $scope.isTask=true;
        }else if($scope.stageTrainObj.hasOwnProperty('knowledge_Id')){
            $scope.isTask=false;
            if($scope.stageTrainObj.know_select_course){
                $scope.selType(1);
            }else if($scope.stageTrainObj.know_select_exam){
                $scope.selectType=2;
                $scope.selType(2);
            }else if($scope.stageTrainObj.know_select_que){
                $scope.selectType=3;
                $scope.selType(3);
            //订单过来的 不需要题库
            //需要课程  和试卷
            }else if(!$scope.showKnow){
                $scope.selType(1);
                $scope.stageTrainObj.know_select_course=true;
                $scope.stageTrainObj.know_select_exam=true;
                $scope.stageTrainObj.know_select_que=false;
            }
            
        }
        //请求登录人对应的选中的任务 的任务进度   参数：arrangeId   userId
     
        ST.findOneProgress({ arrangeId:  $scope.stageTrainObj.id, userId: sysUserInfo.getuserinfo().user_ID }).then(function (response) {
            if (response.errorcode == 0 && response.data != null && response.data != undefined && response.data != "") {
                if (response.data.json_details != null && response.data.json_details != "" && response.data.json_details != undefined) {
                    $scope.completeStr = response.data.json_details;
                } else {
                    $scope.completeStr = "-1";
                }
            } else {
                $scope.completeStr = "-1"; 
            }
            // console.log(response.data.json_details);
            
        });
        // console.log( $scope.completeStr);
        

        // if ($scope.stageTrainObj.isOpen) {  // 展开时查询
        //     if ($scope.stageTrainObj.hasOwnProperty('arragetype') && typeof ($scope.stageTrainObj.arragetype) == "string") {
        //         $scope.stageTrainObj.arragetype = JSON.parse($scope.stageTrainObj.arragetype);
        //     }
        //     console.log($scope.stageTrainObj.arragetype);
            
        //     var courseids = "";
        //     $scope.stageTrainObj.arragetype.forEach(function (arrageobj, index) {
        //         if (arrageobj.kscList.length > 0) {
        //             arrageobj.kscList.forEach(function (courseobj, cindex) {
        //                 if (courseobj.hasOwnProperty("selectType") && courseobj.selectType == 2) {
        //                     courseids += (courseids.length > 0 ? ',' : "") + courseobj.course_Id;
        //                 }
        //             });
        //         }
        //     });
        //     if (courseids.length > 0) {
        //         RTS.findExpireState({ xid: courseids, orgid: sysUserInfo.getuserinfo().organization_ID }).then(function (response) {
        //             if (response.errorcode == 0) {
        //                 var hasids = response.datas.join(",");
        //                 $scope.stageTrainObj.arragetype.forEach(function (arrageobj, index) {
        //                     if (arrageobj.kscList.length > 0) {
        //                         arrageobj.kscList.forEach(function (courseobj, cindex) {
        //                             if (courseobj.hasOwnProperty("selectType") && courseobj.selectType == 2) {
        //                                 if (hasids.indexOf(courseobj.course_Id) != -1) {
        //                                     courseobj.expire = true;
        //                                 } else {
        //                                     courseobj.expire = false;
        //                                 }
        //                             }
        //                         });
        //                     }
        //                 });

        //             } else {
        //                 //请求失败
        //             }
        //             $scope.initArrange($scope.stageTrainObj);
        //         });
        //         //无共享课程
        //     } else {
        //         $scope.initArrange($scope.stageTrainObj);
        //     }


        // }
    }
    //排序的方法
    $scope.initArrange = function (stageTrainObj) {
        // 初始化阶段 默认第一阶段
        $scope.selStageFlag = 1;
        if ($scope.stageTrainObj.hasOwnProperty('arrage') && typeof ($scope.stageTrainObj.arrage) == "string") {
            $scope.stageTrainObj.arrage = JSON.parse($scope.stageTrainObj.arrage);
        }
        //&& typeof ($scope.stageTrainObj.arragetype) == "string"
        if ($scope.stageTrainObj.hasOwnProperty('arragetype')) {
            // 后台传入的参数需要解析 重新赋值于自身
            // $scope.stageTrainObj.arragetype = JSON.parse($scope.stageTrainObj.arragetype);
            //获取任务进度
            $scope.getArrangeProgress($scope.stageTrainObj);
            //汇总数据，为了排序
            $scope.stageTrainObj.totleList = [];
            $scope.stageTrainObj.arragetype.forEach(function (keyObj, index) {
                var totleList = [];
                if (keyObj.hasOwnProperty('kssList')) { // 知识结构
                    keyObj.kssList.forEach(function (data, index) {
                        data.type = 3;
                        if (data.order == undefined || data.order == null || data.order == "") {
                            data.order = 0;
                        }
                        totleList.push(data);
                    });
                }
                if (keyObj.hasOwnProperty('kseList')) { // 试卷
                    keyObj.kseList.forEach(function (data, index) {
                        data.type = 2;
                        if (data.order == undefined || data.order == null || data.order == "") {
                            data.order = 0;
                        }
                        totleList.push(data);
                    });
                }
                if (keyObj.hasOwnProperty('kscList')) { //课程
                    keyObj.kscList.forEach(function (data, index) {
                        data.type = 1;
                        if (data.order == undefined || data.order == null || data.order == "") {
                            data.order = 0;
                        }
                        totleList.push(data);
                    });
                }
                keyObj.totleList = totleList;
                //强制任务学习才排序
                if ($scope.stageTrainObj.arrage.isOrder != undefined && $scope.stageTrainObj.arrage.isOrder) {
                    keyObj.totleList = keyObj.totleList.sort(function (obj1, obj2) {
                        return obj1.order - obj2.order;
                    })
                }
            });
            $scope.isTask=true;
        }else if($scope.stageTrainObj.hasOwnProperty('knowledge_Id')){
            $scope.isTask=false;
            if(scope.stageTrainObj.know_select_course){
                $scope.selType(1);
            }else if(scope.stageTrainObj.know_select_exam){
                $scope.selectType=2;
                $scope.selType(2);
            }else if(scope.stageTrainObj.know_select_que){
                $scope.selectType=3;
                $scope.selType(3);
            //订单过来的 不需要题库
            //需要课程  和试卷
            }else if(!scope.showKnow){
                $scope.selType(1);
                $scope.stageTrainObj.know_select_course=true;
                $scope.stageTrainObj.know_select_exam=true;
                $scope.stageTrainObj.know_select_que=false;
            }
            
        }
    }
    //报名任务
    $scope.signUpArrange = function (stageTrainObj) {
        ST.addEnrollInfo({ xid: $scope.stageTrainObj.id, userid: sysUserInfo.getuserinfo().user_ID, type: 1 }).then(function (response) {
            if (response.errorcode == 0) {
                Msg.warning("报名成功，请耐心等待管理员审核！")
                $scope.stageTrainObj.warnMsg = "您的报名申请已提交，正在审核中，请耐心等待！";
                $scope.stageTrainObj.signUpState = 1;
            } else if (response.errorcode == 27) {
                Msg.warning("报名任务不存在！")
            } else if (response.errorcode == 28) {
                Msg.warning("报名审核中，请耐心等待！")
            } else if (response.errorcode == 29) {
                Msg.warning("您已经报过名了，请不要重复操作！")
            } else if (response.errorcode == 30) {
                Msg.warning("您的报名审核失败，请联系管理员！")
            }
        });
    }
    //请求登录人对应的选中的任务 的任务进度   参数：arrangeId   userId
    $scope.getArrangeProgress = function (arrangeObj) {
        ST.findOneProgress({ arrangeId: arrangeObj.id, userId: sysUserInfo.getuserinfo().user_ID }).then(function (response) {
            if (response.errorcode == 0 && response.data != null && response.data != undefined && response.data != "") {
                if (response.data.json_details != null && response.data.json_details != "" && response.data.json_details != undefined) {
                    arrangeObj.completeStr = response.data.json_details;
                } else {
                    arrangeObj.completeStr = "-1";
                }
            } else {
                arrangeObj.completeStr = "-1";
            }
        });
    }
    //选中阶段
    $scope.selectStage = function (stageItem, trainObj) {
        $scope.selStageFlag = stageItem.key;
    }
    // 选择要筛选的
    $scope.selTrainList = function (type) {
        $scope.stuListParams.state = type; //查看全部的时候从数据库筛选
        if (type == 5 || type == 6) {
            $scope.isIconList = false;
        }
        $scope.isTrainList = type;
        $scope.stuListParams.name = '';
        $scope.getStuTrainList();
    }
    //验证内容
    //判断数组中四属性是否存在
    $scope.isTaskNotNull = function (list) {
        if (!list.hasOwnProperty('kssList')) // 知识结构
            list.kssList = [];
        if (!list.hasOwnProperty('kseList')) // 试卷
            list.kseList = [];
        if (!list.hasOwnProperty('ksfList')) // 文件 
            list.ksfList = [];
        if (!list.hasOwnProperty('kscList')) //课程
            list.kscList = [];
        if (!list.hasOwnProperty('value')) //课程
            list.value = "";
        return list;
    }

    //配置分页
    $scope.paginationConf = {
        currentPage: 1, //$location.search().currentPage ? $location.search().currentPage :  当前页码
        totalItems: 0,  // 总的记录数
        itemsPerPage: 8, // 每页显示多少条        
        perPageOptions: [8, 16],   // 每页显示记录数        
        onChange: function () {
            $scope.paginationConf.currentPage = $scope.paginationConf.currentPage == 0 ? 1 : $scope.paginationConf.currentPage;
            if ((parseInt($scope.stuListParams.pageIndex) != parseInt($scope.paginationConf.currentPage)) || (parseInt($scope.stuListParams.pageSize) != parseInt($scope.paginationConf.itemsPerPage))) {
                if ($scope.paginationConf.currentPage == 0) { $scope.paginationConf.currentPage = 1; }
                $scope.stuListParams.pageIndex = $scope.paginationConf.currentPage;
                $scope.stuListParams.pageSize = $scope.paginationConf.itemsPerPage;
                $scope.getStuTrainList();
            }
        }
    };
    $scope.init()
    $scope.getPaperUrl = function (paperUrl, coun) {
        // console.log(paperUrl,coun);
        $scope.paperUrlList = paperUrl.split("/");
        $scope.paperNum = $scope.paperUrlList[$scope.paperUrlList.length - 1].split(".")[0];
        if ($scope.paperNum != undefined && $scope.paperNum != null && $scope.paperNum != "") {
            $scope.paperNum;
            $scope.paperReadNum = parseInt(Math.random() * coun + 1);
            $scope.paperUrlList[$scope.paperUrlList.length - 1] = ($scope.paperReadNum == 0) ? "1.html" : $scope.paperReadNum + ".html";
            $scope.paperUrl = $scope.paperUrlList.join("/");
        }
        if ($scope.paperReadNum == 0) {
            $scope.paperReadNum = 1;
        }
        // console.log($scope.paperUrl);
        
        return $scope.paperUrl;
    }
    $scope.commonUrl = "";
    //***************************************************知识分类开始*******************************************************************/
    $scope.selectType=1;
    //课程试卷筛选 、
    $scope.selType=function(index){
        // scope.isTask = true
        $scope.selectType=index;
        if(index!=3){
            if(index==1&&$scope.stageTrainObj.kscList!=undefined){
                return;
            }
            if(index==2&&$scope.stageTrainObj.kseList!=undefined){
                return;
            }
             //请求登录人对应的选中的任务 的任务进度   参数：arrangeId   userId
            ST.findArrangeStage({ knowledgeids: $scope.stageTrainObj.knowledge_Id, state:index}).then(function (response) {
                if (response.errorcode == 0) {
                    if(index==1){
                        $scope.stageTrainObj.kscList=response.datas;
                    }else{
                        $scope.stageTrainObj.kseList=response.datas;
                    }
                } else {
                    $scope.completeStr = "-1";
                }
          
              
                
                
            });
        }
    }
    
     /****************************************************验证强制学校******************************************************/
     $scope.validateTask=function(item){

        //编程思路
         //当前有培训任务集合与学习记录
         //1、先判断当前在学习，第几个阶段，如果不是第一个阶段，检查上一个阶段有没有学完
         //2、如果上一个阶段学完了，检查当前学习阶段内的课程，要学的课程排在第几，上一个课程是否学员
         var key = $scope.stageTrainObj.arragetype[$scope.selStageFlag - 1].key; //当前是第几阶段，从2开始判读
         
         //强制学习
             if($scope.stageTrainObj.arrage!=undefined&&$scope.stageTrainObj.arrage.isOrder){
                 
                 if (key > 1) {
                     //强制学习
                     if($scope.stageTrainObj.arrage!=undefined&&$scope.stageTrainObj.arrage.isOrder){
                         var shangjieduan = $scope.stageTrainObj.arragetype[key - 2];
                         for (var i = 0; i < shangjieduan.kscList.length; i++) {
                             var id = shangjieduan.kscList[i].course_Id;
                             if ($scope.completeStr.indexOf(id) == -1) {
                                 Msg.warning("提示", "您上一个阶段(" + shangjieduan.kscList[i].course_Name + ")还未完成噢！");
                                 return;
                                 break;
                             }
                         }
                         for (var i = 0; i < shangjieduan.kseList.length; i++) {
                             var id = shangjieduan.kseList[i].paperId;
                             if ($scope.completeStr.indexOf(id) == -1) {
                                 Msg.warning("提示", "您上一个阶段(" + shangjieduan.kseList[i].paperName + ")还未完成噢！");
                                 return;
                                 break;
                             }
                         }
                         for (var i = 0; i < shangjieduan.kssList.length; i++) {
                             var id = shangjieduan.kssList[i].knowledge_Id;
                             if ($scope.completeStr.indexOf(id) == -1) {
                                  Msg.warning("提示","您上一个阶段还未完成噢！");
                                 return;
                                 break;
                             }
                         }
                     }
                 }
                 
                 var preObj=null;
                 //匹配前一个课程
                 $scope.stageTrainObj.arragetype[$scope.selStageFlag-1].totleList.forEach(function(data,index){
                     if(preObj==null){
                        //课程
                         if(item.type==1&&data.type==1){
                             if(data.course_Id==item.course_Id){
                                 if(index==0){
                                     preObj="0";
                                 }else{
                                     preObj=$scope.stageTrainObj.arragetype[$scope.selStageFlag-1].totleList[index-1];
                                 }
                             }
                         //试卷
                         }else if(item.type==2&&data.type==2){
                             if(data.paperId==item.paperId){
                                 if(index==0){
                                     preObj="0";
                                 }else{
                                     preObj=$scope.stageTrainObj.arragetype[$scope.selStageFlag-1].totleList[index-1];
                                 }
                             }
                         //知识分类
                         }else if(item.type==3&&data.type==3){
                             if(data.knowledge_Id==item.knowledge_Id){
                                 if(index==0){
                                     preObj="0";
                                 }else{
                                     preObj=$scope.stageTrainObj.arragetype[$scope.selStageFlag-1].totleList[index-1];
                                 }
                             }
                         }
                     }
                 });

                  //课程
                 if(preObj.type==1){
                     if($scope.completeStr.indexOf(preObj.course_Id)==-1){
                         Msg.warning("提示","请先学习课程【"+preObj.course_Name+"】");
                         return false;
                     }else{
                         return true;
                     }
                 //试卷
                 }else if(preObj.type==2){
                     if($scope.completeStr.indexOf(preObj.paperId)==-1){
                         Msg.warning("提示","请先考核试卷【"+preObj.paperName+"】");
                         return false;
                     }else{
                         return true;
                     }
                 //知识分类
                 }else if(preObj.type==3){
                     if($scope.completeStr.indexOf(preObj.knowledge_Id)==-1){
                         Msg.warning("提示","请先学习大纲【"+preObj.knowledge_Name+"】");
                         return false;
                     }else{
                         return true;
                     }
                 }else{
                     return true;
                 }

             }else{
                 return true;
             }
        }
    // 打开连接
    $scope.openUrlLink = function (item, taskObj,key) {

        if(key!=undefined){
            $scope.selStageFlag=key;
        }

        //验证是否需要报名,
        if ($scope.stageTrainObj.isReviewed) {
            if ($scope.stageTrainObj.signUpState == 0) {
                Msg.warning("请先报名参与该任务！");
                return;
            } else if ($scope.stageTrainObj.signUpState == 1) {
                Msg.warning("报名审核中，请耐心等待！");
                return;
            } else if ($scope.stageTrainObj.signUpState == 3) {
                Msg.warning("报名审核失败，详情请联系管理员");
                return;
            }
        }
        // console.log($scope.completeStr.indexOf(item.course_Id)!=-1);
        // console.log($scope.completeStr.indexOf(item.paperId)!=-1);
        // console.log($scope.completeStr.indexOf(item.knowledge_Id)!=-1);
        // console.log($scope.completeStr.indexOf(item.courseId)!=-1);
        
        var id=$stateParams.renwuobj.id;
        
        //验证是否强制学习（上一个是否学习完成）
        if($scope.isTask){
            var a=$scope.validateTask(item,taskObj);
            // var id = taskObj.id;
            if(!a){
                return;
             
            }
        }
      
        //课程
        if (item.hasOwnProperty('course_Id')) {
            //if (item.hasOwnProperty("selectType") && item.selectType == 2 && !item.expire) {
            //    Msg.warning("该课程已过期，请联系管理员！");
            //    return;
            //}
            //预览
            var url = "";
            if ($rootScope.fileurl.indexOf("http") != -1) {
                url = $rootScope.upurl + '/dispatcher/redirect?url=' + encodeURI(encodeURI($rootScope.fileurl + "/resources/template/" + item.course_Id + ".html?arrangeId=" + id + "&token=" + sysUserInfo.getuserinfotoken()));
            } else {
                url = $rootScope.upurl + '/dispatcher/redirect?url=' + encodeURI(encodeURI(window.location.protocol + $rootScope.fileurl + "/resources/template/" + item.course_Id + ".html?arrangeId=" + id + "&token=" + sysUserInfo.getuserinfotoken()));
            }
            window.open(url);
            //试卷
        }//课程
        else if (item.hasOwnProperty('courseId')) {
            //预览
            if(commonFileUrl.indexOf("http")!=-1){
                 url = commonUrl + '/dispatcher/redirect?url=' + encodeURI(encodeURI(commonFileUrl + "/resources/template/" + item.courseId + ".html?arrangeId=" + id + "&token=" + sysUserInfo.getuserinfotoken()));
            }else{
                url = commonUrl + '/dispatcher/redirect?url=' + encodeURI(encodeURI(window.location.protocol+commonFileUrl + "/resources/template/" + item.courseId + ".html?arrangeId=" + id + "&token=" + sysUserInfo.getuserinfotoken()));
            }
            window.open(url);
        //试卷
        } else if (item.hasOwnProperty('paperId')) {
            $scope.paperReadNum = 0;
            if (item.paper_Random == "0") {
                item.url = $scope.getPaperUrl(item.url, item.paperCount)
            }
            //         $scope.commonUrl =$rootScope.fileurl+item.url+"?arrangeId="+id+"&userid="+sysUserInfo.getuserinfo().user_ID+"&token="+sysUserInfo.getuserinfotoken()+"&date="+new Date();
            $scope.commonUrl = $rootScope.fileurl + item.url + "?arrangeId=" + id + "&userid=" + sysUserInfo.getuserinfo().user_ID + "&token=" + sysUserInfo.getuserinfotoken() + "&random=" + ($scope.paperReadNum == undefined ? 0 : $scope.paperReadNum) + "&date=" + new Date();

            // 判断一下考试次数
            if (item.examCount > 0) {
                ST.getExamNum({ "paperid": item.paperId, "userid": sysUserInfo.getuserinfo().user_ID,"arrangId":id  }).then(function (data) {
                    if (item.examCount <= data.data) {
                        Msg.warning("您的考试次数用完了");
                        return;
                    } else {
                        $timeout(function () { document.getElementById("commonHref").click(); }, 50);
                    }
                });
            } else {
                $timeout(function () { document.getElementById("commonHref").click(); }, 50);
            }

            //分类
        }else if (item.hasOwnProperty('knowledge_Id')&&(!$scope.isTask)) {
            $scope.commonUrl = "/member/index.html#/home/stuquelist/"+id+"/"+item.knowledge_Id+"/"+(item.know_select_que_type?item.know_select_que_type:0)+"/"+(item.know_select_que_num?item.know_select_que_num:0)+"/0/"+item.knowledge_Name+"/"+id+"/"+item.knowledge_Id+"/"+item.knowledge_Name+"/0///";
        
           window.open($scope.commonUrl);
      
        }  else if (item.hasOwnProperty('knowledge_Id')) {
            //打开分类预览
            item.id = id; //赋值任务id
            // console.log(item); 
            
            $scope.opentoDetail(item);

        } else {
            Msg.warning("未识别类型！");
            return;
        }

    }
    //当前任务详细页改为知识分类也
    $scope.opentoDetail=function(obj){
        //验证是否需要报名,
       //  scope.isTask = true
       if($scope.stageTrainObj.isReviewed){
           if($scope.stageTrainObj.signUpState==0){
               Msg.warning("请先报名参与该任务！");
               return;
           }else if(scope.stageTrainObj.signUpState==1){
               Msg.warning("报名审核中，请耐心等待！");
               return;
           }else if(scope.stageTrainObj.signUpState==3){
               Msg.warning("报名审核失败，详情请联系管理员");
               return;
           }
       }
       var a=$scope.validateTask(obj);
       if(!a){
           return;
       }
       $scope.stageTrainObj=obj;
       $scope.stageTrainObj.id= $stateParams.renwuobj.id;
       $scope.init();
   }
} ]);  